package com.atguigu.spzx.cloud.user.controller;


import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.atguigu.spzx.cloud.model.entity.User;
import com.atguigu.spzx.cloud.user.service.UserService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.net.http.HttpRequest;

@RestController
@RequestMapping(value = "/api/user")
@Slf4j
@RefreshScope
public class UserController {

    @Autowired
    private UserService userService ;

    @Value("${name}")

    private String name ;

    @GetMapping(value = "/findUserByUserId/{userId}")
    @SentinelResource(value = "findUserByUserId")
    public User findUserByUserId(@PathVariable(value = "userId") Long userId/*, HttpServletRequest request*/) {
//        log.info("UserController...findUserByUserId方法执行了... ,name: {} " , name);
//        log.info("UserController...findUserByUserId方法执行了... ,header: {} " , header);
//        String header = request.getHeader("Truth");
//        System.out.println(header);
       try {
           int a = 10/0;
        }catch(Exception e){
            log.error("异常信息：{}",e.getMessage());
       }
        return userService.findUserByUserId(userId) ;
    }

    @GetMapping(value = "/test1")
    public String test1() {
        userService.queryUsers();
        return "test1" ;
    }

    @GetMapping(value = "/test2")
    public String test2() {
        userService.queryUsers();
        return "test2" ;
    }



}